package com.example.demo.controller;

import com.example.demo.service.SysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Pay_SysController {

    private final SysService sysService;

    @Autowired
    public Pay_SysController(SysService sysService) {
        this.sysService = sysService;
    }

    @PostMapping("/payment/pay")
    public ResponseEntity<String> makePayment(@RequestParam("amount") double amount) {
        if (amount <= 0) {
            return new ResponseEntity<>("Payment failed", HttpStatus.BAD_REQUEST);
        }
        if (sysService.makePayment(amount)) {
            return new ResponseEntity<>("Payment successful", HttpStatus.OK);
        } else {
            return new ResponseEntity<>("Payment failed", HttpStatus.BAD_REQUEST);
        }
    }
}
